using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
using System.Data.SqlTypes;
using System.Text;

namespace Data_Access_Tier
{
	public class HRM_CANDIDATE_MARKData : DatabaseObjectBase
	{
		public HRM_CANDIDATE_MARKData()
		{
			Initialize(true);
		}
		public HRM_CANDIDATE_MARKData(Boolean newConnection)
		{
			Initialize(newConnection);
		}

		public Int32 HRM_CANDIDATE_MARK_Insert(Guid MarkID, String CandidateCode, Double Mark1, Double Mark2, Double Mark3, DateTime Date1, DateTime Date2, DateTime Date3, String Comment, Boolean IsPass)
		{
			try
			{
				if (_dbconn.State != ConnectionState.Open)
					_dbconn.Open();
				_dbadapter.InsertCommand = new SqlCommand("HRM_CANDIDATE_MARK_Insert");
				_dbadapter.InsertCommand.CommandType = CommandType.StoredProcedure;
				_dbadapter.InsertCommand.Connection = _dbconn;
				_trans = _dbconn.BeginTransaction();
				_dbadapter.InsertCommand.Transaction = _trans;
				_dbadapter.InsertCommand.Parameters.Clear();
				_dbadapter.InsertCommand.Parameters.Add(new SqlParameter("@MarkID", SqlDbType.UniqueIdentifier));
				_dbadapter.InsertCommand.Parameters.Add(new SqlParameter("@CandidateCode", SqlDbType.VarChar, 20));
				_dbadapter.InsertCommand.Parameters.Add(new SqlParameter("@Mark1", SqlDbType.Float));
				_dbadapter.InsertCommand.Parameters.Add(new SqlParameter("@Mark2", SqlDbType.Float));
				_dbadapter.InsertCommand.Parameters.Add(new SqlParameter("@Mark3", SqlDbType.Float));
				_dbadapter.InsertCommand.Parameters.Add(new SqlParameter("@Date1", SqlDbType.DateTime));
				_dbadapter.InsertCommand.Parameters.Add(new SqlParameter("@Date2", SqlDbType.DateTime));
				_dbadapter.InsertCommand.Parameters.Add(new SqlParameter("@Date3", SqlDbType.DateTime));
				_dbadapter.InsertCommand.Parameters.Add(new SqlParameter("@Comment", SqlDbType.NVarChar, 4000));
				_dbadapter.InsertCommand.Parameters.Add(new SqlParameter("@IsPass", SqlDbType.Bit));
				_dbadapter.InsertCommand.Prepare();
				SqlGuid MarkIDSQL = MarkID;
				_dbadapter.InsertCommand.Parameters["@MarkID"].Value = MarkIDSQL;
				SqlString CandidateCodeSQL = CandidateCode;
				_dbadapter.InsertCommand.Parameters["@CandidateCode"].Value = CandidateCodeSQL;
				SqlDouble Mark1SQL = Mark1;
				_dbadapter.InsertCommand.Parameters["@Mark1"].Value = Mark1SQL;
				SqlDouble Mark2SQL = Mark2;
				_dbadapter.InsertCommand.Parameters["@Mark2"].Value = Mark2SQL;
				SqlDouble Mark3SQL = Mark3;
				_dbadapter.InsertCommand.Parameters["@Mark3"].Value = Mark3SQL;
				SqlDateTime Date1SQL = SqlDateTime.Null;
				if (Date1 > DateTime.MinValue)
				{
					try
					{
						Date1SQL = Date1;
					}
					catch (Exception eDate1)
					{
						String Date1Message = eDate1.Message;
						Date1SQL = SqlDateTime.Null;
					}
				}
				_dbadapter.InsertCommand.Parameters["@Date1"].Value = Date1SQL;
				SqlDateTime Date2SQL = SqlDateTime.Null;
				if (Date2 > DateTime.MinValue)
				{
					try
					{
						Date2SQL = Date2;
					}
					catch (Exception eDate2)
					{
						String Date2Message = eDate2.Message;
						Date2SQL = SqlDateTime.Null;
					}
				}
				_dbadapter.InsertCommand.Parameters["@Date2"].Value = Date2SQL;
				SqlDateTime Date3SQL = SqlDateTime.Null;
				if (Date3 > DateTime.MinValue)
				{
					try
					{
						Date3SQL = Date3;
					}
					catch (Exception eDate3)
					{
						String Date3Message = eDate3.Message;
						Date3SQL = SqlDateTime.Null;
					}
				}
				_dbadapter.InsertCommand.Parameters["@Date3"].Value = Date3SQL;
				SqlString CommentSQL = Comment;
				_dbadapter.InsertCommand.Parameters["@Comment"].Value = CommentSQL;
				SqlBoolean IsPassSQL = IsPass;
				_dbadapter.InsertCommand.Parameters["@IsPass"].Value = IsPassSQL;
				Int32 returnvalue = Convert.ToInt32(_dbadapter.InsertCommand.ExecuteScalar());

				_trans.Commit();
				return returnvalue;
			}
			catch (SqlException e)
			{
				try
				{
					_trans.Rollback();
				}
				catch (SqlException ex)
				{
					throw new Exception("SQL Rollback Error: HRM_CANDIDATE_MARK_Insert: " + ex.Message, ex);
				}
				throw new Exception("SQL Error: HRM_CANDIDATE_MARK_Insert: " + e.Message, e);
			}
			finally
			{
				if (_dbadapter.InsertCommand != null)
					_dbadapter.InsertCommand.Dispose();
				CloseConnection();
			}
		}
		public Int32 HRM_CANDIDATE_MARK_Update(Guid MarkID, String CandidateCode, Double Mark1, Double Mark2, Double Mark3, DateTime Date1, DateTime Date2, DateTime Date3, String Comment, Boolean IsPass)
		{
			try
			{
				if (_dbconn.State != ConnectionState.Open)
					_dbconn.Open();
				_dbadapter.UpdateCommand = new SqlCommand("HRM_CANDIDATE_MARK_Update");
				_dbadapter.UpdateCommand.CommandType = CommandType.StoredProcedure;
				_dbadapter.UpdateCommand.Connection = _dbconn;

				_trans = _dbconn.BeginTransaction();
				_dbadapter.UpdateCommand.Transaction = _trans;

				_dbadapter.UpdateCommand.Parameters.Clear();
				_dbadapter.UpdateCommand.Parameters.Add(new SqlParameter("@MarkID", SqlDbType.UniqueIdentifier));
				_dbadapter.UpdateCommand.Parameters.Add(new SqlParameter("@CandidateCode", SqlDbType.VarChar, 20));
				_dbadapter.UpdateCommand.Parameters.Add(new SqlParameter("@Mark1", SqlDbType.Float));
				_dbadapter.UpdateCommand.Parameters.Add(new SqlParameter("@Mark2", SqlDbType.Float));
				_dbadapter.UpdateCommand.Parameters.Add(new SqlParameter("@Mark3", SqlDbType.Float));
				_dbadapter.UpdateCommand.Parameters.Add(new SqlParameter("@Date1", SqlDbType.DateTime));
				_dbadapter.UpdateCommand.Parameters.Add(new SqlParameter("@Date2", SqlDbType.DateTime));
				_dbadapter.UpdateCommand.Parameters.Add(new SqlParameter("@Date3", SqlDbType.DateTime));
				_dbadapter.UpdateCommand.Parameters.Add(new SqlParameter("@Comment", SqlDbType.NVarChar, 4000));
				_dbadapter.UpdateCommand.Parameters.Add(new SqlParameter("@IsPass", SqlDbType.Bit));
				_dbadapter.UpdateCommand.Prepare();
				SqlGuid MarkIDSQL = MarkID;
				_dbadapter.UpdateCommand.Parameters["@MarkID"].Value = MarkIDSQL;
				SqlString CandidateCodeSQL = CandidateCode;
				_dbadapter.UpdateCommand.Parameters["@CandidateCode"].Value = CandidateCodeSQL;
				SqlDouble Mark1SQL = Mark1;
				_dbadapter.UpdateCommand.Parameters["@Mark1"].Value = Mark1SQL;
				SqlDouble Mark2SQL = Mark2;
				_dbadapter.UpdateCommand.Parameters["@Mark2"].Value = Mark2SQL;
				SqlDouble Mark3SQL = Mark3;
				_dbadapter.UpdateCommand.Parameters["@Mark3"].Value = Mark3SQL;
				SqlDateTime Date1SQL = SqlDateTime.Null;
				if (Date1 > DateTime.MinValue)
				{
					try
					{
						Date1SQL = Date1;
					}
					catch (Exception eDate1)
					{
						String Date1Message = eDate1.Message;
						Date1SQL = SqlDateTime.Null;
					}
				}
				_dbadapter.UpdateCommand.Parameters["@Date1"].Value = Date1SQL;
				SqlDateTime Date2SQL = SqlDateTime.Null;
				if (Date2 > DateTime.MinValue)
				{
					try
					{
						Date2SQL = Date2;
					}
					catch (Exception eDate2)
					{
						String Date2Message = eDate2.Message;
						Date2SQL = SqlDateTime.Null;
					}
				}
				_dbadapter.UpdateCommand.Parameters["@Date2"].Value = Date2SQL;
				SqlDateTime Date3SQL = SqlDateTime.Null;
				if (Date3 > DateTime.MinValue)
				{
					try
					{
						Date3SQL = Date3;
					}
					catch (Exception eDate3)
					{
						String Date3Message = eDate3.Message;
						Date3SQL = SqlDateTime.Null;
					}
				}
				_dbadapter.UpdateCommand.Parameters["@Date3"].Value = Date3SQL;
				SqlString CommentSQL = Comment;
				_dbadapter.UpdateCommand.Parameters["@Comment"].Value = CommentSQL;
				SqlBoolean IsPassSQL = IsPass;
				_dbadapter.UpdateCommand.Parameters["@IsPass"].Value = IsPassSQL;
				Int32 returnvalue = Convert.ToInt32(_dbadapter.UpdateCommand.ExecuteScalar());

				_trans.Commit();
				return returnvalue;
			}
			catch (SqlException e)
			{
				try
				{
					_trans.Rollback();
				}
				catch (SqlException ex)
				{
					throw new Exception("SQL Rollback Error: HRM_CANDIDATE_MARK_Update: " + ex.Message, ex);
				}
				throw new Exception("SQL Error: HRM_CANDIDATE_MARK_Update: " + e.Message, e);
			}
			finally
			{
				if (_dbadapter.UpdateCommand != null)
					_dbadapter.UpdateCommand.Dispose();
				CloseConnection();
			}
		}
		public Int32 HRM_CANDIDATE_MARK_Disable(Guid MarkID, ref Boolean Enabled)
		{
			try
			{
				if (_dbconn.State != ConnectionState.Open)
					_dbconn.Open();
				_dbadapter.UpdateCommand = new SqlCommand("HRM_CANDIDATE_MARK_Disable");
				_dbadapter.UpdateCommand.CommandType = CommandType.StoredProcedure;
				_dbadapter.UpdateCommand.Connection = _dbconn;

				_trans = _dbconn.BeginTransaction();
				_dbadapter.UpdateCommand.Transaction = _trans;

				_dbadapter.UpdateCommand.Parameters.Clear();
				_dbadapter.UpdateCommand.Parameters.Add(new SqlParameter("@MarkID", SqlDbType.UniqueIdentifier));
				_dbadapter.UpdateCommand.Parameters.Add(new SqlParameter("@enabled", SqlDbType.Bit));
				_dbadapter.UpdateCommand.Prepare();
				SqlGuid MarkIDSQL = MarkID;
				_dbadapter.UpdateCommand.Parameters["@MarkID"].Value = MarkIDSQL;
				_dbadapter.UpdateCommand.Parameters["@enabled"].Direction = ParameterDirection.Output;
				Int32 returnvalue = Convert.ToInt32(_dbadapter.UpdateCommand.ExecuteScalar());

				_trans.Commit();
				return returnvalue;
			}
			catch (SqlException e)
			{
				try
				{
					_trans.Rollback();
				}
				catch (SqlException ex)
				{
					throw new Exception("SQL Rollback Error: HRM_CANDIDATE_MARK_Disable: " + ex.Message, ex);
				}
				throw new Exception("SQL Error: HRM_CANDIDATE_MARK_Disable: " + e.Message, e);
			}
			finally
			{
				if (_dbadapter.UpdateCommand != null)
					_dbadapter.UpdateCommand.Dispose();
				CloseConnection();
			}
		}
		public Int32 HRM_CANDIDATE_MARK_Delete(Guid MarkID)
		{
			try
			{
				if (_dbconn.State != ConnectionState.Open)
					_dbconn.Open();
				_dbadapter.DeleteCommand = new SqlCommand("HRM_CANDIDATE_MARK_Delete");
				_dbadapter.DeleteCommand.CommandType = CommandType.StoredProcedure;
				_dbadapter.DeleteCommand.Connection = _dbconn;

				_trans = _dbconn.BeginTransaction();
				_dbadapter.DeleteCommand.Transaction = _trans;

				_dbadapter.DeleteCommand.Parameters.Clear();
				_dbadapter.DeleteCommand.Parameters.Add(new SqlParameter("@MarkID", SqlDbType.UniqueIdentifier));
				_dbadapter.DeleteCommand.Prepare();
				SqlGuid MarkIDSQL = MarkID;
				_dbadapter.DeleteCommand.Parameters["@MarkID"].Value = MarkIDSQL;
				Int32 returnvalue = Convert.ToInt32(_dbadapter.DeleteCommand.ExecuteScalar());

				_trans.Commit();
				return returnvalue;
			}
			catch (SqlException e)
			{
				try
				{
					_trans.Rollback();
				}
				catch (SqlException ex)
				{
					throw new Exception("SQL Rollback Error: HRM_CANDIDATE_MARK_Delete: " + ex.Message, ex);
				}
				throw new Exception("SQL Error: HRM_CANDIDATE_MARK_Delete: " + e.Message, e);
			}
			finally
			{
				if (_dbadapter.DeleteCommand != null)
					_dbadapter.DeleteCommand.Dispose();
				CloseConnection();
			}
		}
		public Int32 HRM_CANDIDATE_MARK_Save(Guid MarkID, String CandidateCode, Double Mark1, Double Mark2, Double Mark3, DateTime Date1, DateTime Date2, DateTime Date3, String Comment, Boolean IsPass)
		{
			try
			{
				if (_dbconn.State != ConnectionState.Open)
					_dbconn.Open();
				_dbadapter.UpdateCommand = new SqlCommand("HRM_CANDIDATE_MARK_Save");
				_dbadapter.UpdateCommand.CommandType = CommandType.StoredProcedure;
				_dbadapter.UpdateCommand.Connection = _dbconn;

				_trans = _dbconn.BeginTransaction();
				_dbadapter.UpdateCommand.Transaction = _trans;

				_dbadapter.UpdateCommand.Parameters.Clear();
				_dbadapter.UpdateCommand.Parameters.Add(new SqlParameter("@MarkID", SqlDbType.UniqueIdentifier));
				_dbadapter.UpdateCommand.Parameters.Add(new SqlParameter("@CandidateCode", SqlDbType.VarChar, 20));
				_dbadapter.UpdateCommand.Parameters.Add(new SqlParameter("@Mark1", SqlDbType.Float));
				_dbadapter.UpdateCommand.Parameters.Add(new SqlParameter("@Mark2", SqlDbType.Float));
				_dbadapter.UpdateCommand.Parameters.Add(new SqlParameter("@Mark3", SqlDbType.Float));
				_dbadapter.UpdateCommand.Parameters.Add(new SqlParameter("@Date1", SqlDbType.DateTime));
				_dbadapter.UpdateCommand.Parameters.Add(new SqlParameter("@Date2", SqlDbType.DateTime));
				_dbadapter.UpdateCommand.Parameters.Add(new SqlParameter("@Date3", SqlDbType.DateTime));
				_dbadapter.UpdateCommand.Parameters.Add(new SqlParameter("@Comment", SqlDbType.NVarChar, 4000));
				_dbadapter.UpdateCommand.Parameters.Add(new SqlParameter("@IsPass", SqlDbType.Bit));
				_dbadapter.UpdateCommand.Prepare();
				SqlGuid MarkIDSQL = MarkID;
				_dbadapter.UpdateCommand.Parameters["@MarkID"].Value = MarkIDSQL;
				SqlString CandidateCodeSQL = CandidateCode;
				_dbadapter.UpdateCommand.Parameters["@CandidateCode"].Value = CandidateCodeSQL;
				SqlDouble Mark1SQL = Mark1;
				_dbadapter.UpdateCommand.Parameters["@Mark1"].Value = Mark1SQL;
				SqlDouble Mark2SQL = Mark2;
				_dbadapter.UpdateCommand.Parameters["@Mark2"].Value = Mark2SQL;
				SqlDouble Mark3SQL = Mark3;
				_dbadapter.UpdateCommand.Parameters["@Mark3"].Value = Mark3SQL;
				SqlDateTime Date1SQL = SqlDateTime.Null;
				if (Date1 > DateTime.MinValue)
				{
					try
					{
						Date1SQL = Date1;
					}
					catch (Exception eDate1)
					{
						String Date1Message = eDate1.Message;
						Date1SQL = SqlDateTime.Null;
					}
				}
				_dbadapter.UpdateCommand.Parameters["@Date1"].Value = Date1SQL;
				SqlDateTime Date2SQL = SqlDateTime.Null;
				if (Date2 > DateTime.MinValue)
				{
					try
					{
						Date2SQL = Date2;
					}
					catch (Exception eDate2)
					{
						String Date2Message = eDate2.Message;
						Date2SQL = SqlDateTime.Null;
					}
				}
				_dbadapter.UpdateCommand.Parameters["@Date2"].Value = Date2SQL;
				SqlDateTime Date3SQL = SqlDateTime.Null;
				if (Date3 > DateTime.MinValue)
				{
					try
					{
						Date3SQL = Date3;
					}
					catch (Exception eDate3)
					{
						String Date3Message = eDate3.Message;
						Date3SQL = SqlDateTime.Null;
					}
				}
				_dbadapter.UpdateCommand.Parameters["@Date3"].Value = Date3SQL;
				SqlString CommentSQL = Comment;
				_dbadapter.UpdateCommand.Parameters["@Comment"].Value = CommentSQL;
				SqlBoolean IsPassSQL = IsPass;
				_dbadapter.UpdateCommand.Parameters["@IsPass"].Value = IsPassSQL;
				Int32 returnvalue = Convert.ToInt32(_dbadapter.UpdateCommand.ExecuteScalar());

				_trans.Commit();
				return returnvalue;
			}
			catch (SqlException e)
			{
				try
				{
					_trans.Rollback();
				}
				catch (SqlException ex)
				{
					throw new Exception("SQL Rollback Error: HRM_CANDIDATE_MARK_Save: " + ex.Message, ex);
				}
				throw new Exception("SQL Error: HRM_CANDIDATE_MARK_Save: " + e.Message, e);
			}
			finally
			{
				if (_dbadapter.UpdateCommand != null)
					_dbadapter.UpdateCommand.Dispose();
				CloseConnection();
			}
		}
		public DataSet HRM_CANDIDATE_MARK_GetList()
		{
			try
			{
				if (_dbconn.State != ConnectionState.Open)
					_dbconn.Open();
				_dbadapter.SelectCommand = new SqlCommand("HRM_CANDIDATE_MARK_GetList");
				_dbadapter.SelectCommand.CommandType = CommandType.StoredProcedure;
				_dbadapter.SelectCommand.Connection = _dbconn;
				_dbadapter.SelectCommand.Parameters.Clear();
				_dbadapter.SelectCommand.Prepare();
				_dbadapter.Fill(_data);

				return _data;
			}
			catch (SqlException e)
			{
				throw new Exception("SQL Error: HRM_CANDIDATE_MARK_GetList: " + e.Message, e);
			}
			finally
			{
				if (_dbadapter.SelectCommand != null)
					_dbadapter.SelectCommand.Dispose();
				CloseConnection();
			}
		}
		public DataSet HRM_CANDIDATE_MARK_Get(Guid MarkID)
		{
			try
			{
				if (_dbconn.State != ConnectionState.Open)
					_dbconn.Open();
				_dbadapter.SelectCommand = new SqlCommand("HRM_CANDIDATE_MARK_Get");
				_dbadapter.SelectCommand.CommandType = CommandType.StoredProcedure;
				_dbadapter.SelectCommand.Connection = _dbconn;
				_dbadapter.SelectCommand.Parameters.Clear();
				_dbadapter.SelectCommand.Parameters.Add(new SqlParameter("@MarkID", SqlDbType.UniqueIdentifier));
				_dbadapter.SelectCommand.Prepare();
				SqlGuid MarkIDSQL = MarkID;
				_dbadapter.SelectCommand.Parameters["@MarkID"].Value = MarkIDSQL;
				_dbadapter.Fill(_data);

				return _data;
			}
			catch (SqlException e)
			{
				throw new Exception("SQL Error: HRM_CANDIDATE_MARK_Get: " + e.Message, e);
			}
			finally
			{
				if (_dbadapter.SelectCommand != null)
					_dbadapter.SelectCommand.Dispose();
				CloseConnection();
			}
		}
		public DataSet HRM_CANDIDATE_MARK_GetListByCandidateCode(String CandidateCode)
		{
			try
			{
				if (_dbconn.State != ConnectionState.Open)
					_dbconn.Open();
				_dbadapter.SelectCommand = new SqlCommand("HRM_CANDIDATE_MARK_GetListByCandidateCode");
				_dbadapter.SelectCommand.CommandType = CommandType.StoredProcedure;
				_dbadapter.SelectCommand.Connection = _dbconn;
				_dbadapter.SelectCommand.Parameters.Clear();
				_dbadapter.SelectCommand.Parameters.Add(new SqlParameter("@CandidateCode", SqlDbType.VarChar, 20));
				_dbadapter.SelectCommand.Prepare();
				SqlString CandidateCodeSQL = CandidateCode;
				_dbadapter.SelectCommand.Parameters["@CandidateCode"].Value = CandidateCodeSQL;
				_dbadapter.Fill(_data);

				return _data;
			}
			catch (SqlException e)
			{
				throw new Exception("SQL Error: HRM_CANDIDATE_MARK_GetListByCandidateCode: " + e.Message, e);
			}
			finally
			{
				if (_dbadapter.SelectCommand != null)
					_dbadapter.SelectCommand.Dispose();
				CloseConnection();
			}
		}
	}
}
